<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\AuthController;

Route::get('/', function () {
    return view('landing-refactored');
});

// 测试页面
Route::get('/test', function () {
    return view('test');
});

// 调试认证状态
Route::get('/debug-auth', function () {
    return view('debug-auth');
})->name('debug-auth');

// 产品落地页
Route::get('/landing', function () {
    return view('landing-refactored');
});

// 认证相关路由
Route::middleware('guest')->group(function () {
    // 显示登录/注册页面
    Route::get('/auth', function () {
        return view('auth');
    })->name('auth');
    
    // 登录路由（防止Laravel重定向时找不到）
    Route::get('/login', function () {
        return view('auth');
    })->name('login');
    
    // 注册页面
    Route::get('/register', function () {
        return view('auth');
    })->name('register');
    
    // 处理登录请求
    Route::post('/login', [AuthController::class, 'login'])->name('auth.login');
    
    // 处理注册请求
    Route::post('/register', [AuthController::class, 'register'])->name('auth.register');
    
    // 忘记密码
    Route::get('/forgot-password', [AuthController::class, 'showForgotPasswordForm'])->name('password.request');
    Route::post('/forgot-password', [AuthController::class, 'sendResetLinkEmail'])->name('password.email');
    
    // 重置密码
    Route::get('/reset-password/{token}', [AuthController::class, 'showResetPasswordForm'])->name('password.reset');
    Route::post('/reset-password', [AuthController::class, 'resetPassword'])->name('password.update');
});

// 需要认证的路由
Route::middleware('auth')->group(function () {
    // 仪表板
    Route::get('/dashboard', function () {
        return view('dashboard');
    })->name('dashboard');
    
    // 登出
    Route::post('/logout', [AuthController::class, 'logout'])->name('logout');
    
    // 用户资料
    Route::get('/profile', [AuthController::class, 'profile'])->name('profile');
    Route::put('/profile', [AuthController::class, 'updateProfile'])->name('profile.update');
    
    // API Token 管理（用于插件同步）
    Route::get('/api-token', [AuthController::class, 'getApiToken'])->name('api-token.get');
    Route::delete('/api-token', [AuthController::class, 'revokeApiToken'])->name('api-token.revoke');
});

// 邮箱验证路由
Route::middleware(['auth', 'signed'])->group(function () {
    Route::get('/email/verify/{id}/{hash}', [AuthController::class, 'verifyEmail'])->name('verification.verify');
});

Route::middleware(['auth', 'throttle:6,1'])->group(function () {
    Route::post('/email/verification-notification', [AuthController::class, 'sendVerificationEmail'])->name('verification.send');
});

// 隐私协议页面
Route::view('/privacy-policy', 'privacy-policy')->name('privacy-policy');

// 服务条款页面
Route::view('/terms-of-service', 'terms-of-service')->name('terms-of-service');

// 联系我们页面
Route::view('/contact', 'contact')->name('contact');

// 关于我们页面
Route::view('/about', 'about')->name('about');